
/**
 * @fileoverview Miscellaneous Cookies utility methods.
 * @link http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
 * @link https://developers.google.com/closure/compiler/docs/js-for-compiler
 */



/**
 * Miscellaneous Cookies utility methods.
 * @constructor
 */
dom.Cookies = function() {return null;};


/**
 * Sets a cookie.
 * @param {string} key The name of the cookie.
 * @param {string} value The value of the cookie.
 * @param {number} expires The days after the cookie expires.
 * @param {string=} opt_domain Optional, domain that the cookie is
 *     available to.
 * @static
 */
dom.Cookies.set = function(key, value, expires, opt_domain) {
  dom.document.cookie = escape(key) + '=' + escape(value || '') +
      '; expires=' + (new Date(+new Date + (expires * 864e5)).toGMTString()) +
      '; path=/; domain=' + (opt_domain || dom.document.domain);
};


/**
 * Gets the value for the first cookie with the given name.
 * @param {string} key The name of the cookie to get.
 * @param {string=} opt_default The optional default value.
 * @return {string} The value of the cookie. If no cookie is set this
 *     returns opt_default or undefined if opt_default is not provided.
 * @static
 */
dom.Cookies.get = function(key, opt_default)  {
  return unescape(
      (dom.document.cookie.match(key + '=(.+?)(;|$)') || [])[1] ||
      opt_default || '');
};


/**
 * Removes and expires a cookie.
 * @param {string} key The cookie name.
 * @return {boolean} Whether the cookie existed before it was removed.
 * @static
 */
dom.Cookies.remove = function(key) {
  /** @type {string} */ var value = dom.Cookies.get(key);
  dom.Cookies.set(key, '', 0);
  return !!value;
};
